package main

import (
	"fmt"
	"github.com/casbin/casbin/v2"
	adapter "github.com/casbin/xorm-adapter/v2"
	_ "github.com/go-sql-driver/mysql"
	"log"
)

func main() {
	// 使用MySQL数据库初始化一个orm适配器
	a, err := adapter.NewAdapter("mysql", "root:Ohmylov3@0702@tcp(127.0.0.1:3306)/")
	if err != nil {
		log.Fatalf("error: adapter: %s", err)
	}

	if err != nil {
		log.Fatalf("error: model: %s", err)
	}

	enforcer, err := casbin.NewEnforcer("./doc/rbac_tenant_model.conf", a)
	if err != nil {
		log.Fatalf("error: enforcer: %s", err)
	}

	if err != nil {
		// 处理err
	}

	// 返回权限判断结果
	results, err := enforcer.BatchEnforce([][]interface{}{
		{"alice", "tenant1", "data1", "read"},
		{"alice", "tenant1", "data1", "write"},
		{"bondi", "tenant2", "data2", "read"},
		{"bondi", "tenant2", "data2", "write"},
	})
	fmt.Println(results)
}
